package com.siwei.mes.controller.experiment;

import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.PageGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import com.siwei.mes.entity.experiment.ExperimentPrintRecord;
import com.siwei.mes.service.experiment.ExperimentPrintRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 打印记录相关
 *
 * @author linzi
 * @since 2024-07-27 18:22:12
 */
@Api(value = "打印记录")
@RestController
@RequestMapping("experimentPrintRecord")
public class ExperimentPrintRecordController {
    @Resource
    private ExperimentPrintRecordService experimentPrintRecordService;

    @ApiOperation(value = "新增打印记录")
    @PostMapping("/create")
    public Json create(@RequestBody @Validated(AddGroup.class) ExperimentPrintRecord entity) {
        experimentPrintRecordService.create(entity);
        return Json.succ();
    }

    @ApiOperation(value = "修改打印记录")
    @PostMapping("/update")
    public Json update(@RequestBody @Validated(UpdateGroup.class) ExperimentPrintRecord entity) {
        experimentPrintRecordService.update(entity);
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "删除打印记录")
    @PostMapping("/delete")
    public Json delete(@RequestBody ExperimentPrintRecord entity) {
        experimentPrintRecordService.delete(entity.getId());
        return Json.succ().data(new ApiResult());
    }

    @ApiOperation(value = "分页获取打印记录")
    @PostMapping("/page")
    public Json appPage(@RequestBody @Validated(PageGroup.class) PageQuery<ExperimentPrintRecord, ExperimentPrintRecord> query) {
        return Json.succ().data(experimentPrintRecordService.getPage(query));
    }

    @ApiOperation(value = "根据主键id获取打印记录")
    @GetMapping("loadById")
    public Json loadById(@RequestParam("id") Long id) {
        return Json.succ().data(experimentPrintRecordService.loadById(id));
    }

    @ApiOperation(value = "获取所有打印记录")
    @PostMapping("getAll")
    public Json getAll(@RequestBody ExperimentPrintRecord entity) {
        return Json.succ().data(ApiResult.addList(experimentPrintRecordService.getAll(entity)));
    }

}
